package controller

import (
	"gin_wuwen_back/service"
	"gin_wuwen_back/tool"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"strconv"
)

/*
  @Description: 获取包含自己userid的url
  @receiver tmp
  @param c
*/
func (tmp *RouterControl) GetQcord(c *gin.Context) {

	Func := new(service.Service_func)
	ans, err := Func.Qcord(c)
	if err != nil {
		log.Println(err.Error())
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "生成二维码失败",
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 1,
		"msg":  "生成二维码成功",
		"data": ans,
	})
}

/*
  @Description:将自己和他人的uid返回
  @receiver tmp
  @param c
*/
func (tmp *RouterControl) TalkwithOther(c *gin.Context) {
	userid := c.Param("userid")
	Uid, err := strconv.Atoi(userid)
	if err != nil {
		log.Println(err.Error())
		return

	}
	myuid, ok := c.Get("userid")
	Myuid := myuid.(int)
	if !ok {
		log.Println("lost")
		return
	}
	err = service.Fuc.TalkWithOthers(c, Myuid, Uid)
	if err != nil {
		log.Println(err.Error())
		return
	}

}

/*
  @Description:获取自己的uid
  @receiver tmp
  @param c
*/
func (tmp *RouterControl) GetUid(c *gin.Context) {
	id, ok := c.Get("Userid")
	it := id.(int64)
	uid := strconv.FormatInt(it, 10)
	if !ok {
		log.Println("faild")
		tool.Faild(c,"获取用户id失败")
		return

	}
	c.JSON(http.StatusOK, gin.H{
		"code":    1,
		"data":    uid,
		"message": "这是您的uid请查收",
	})
	return

}
